<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>location</title>

  <style>
    span {
      color:red
    }
  </style>
</head>

<body>
  <a href="http://www.itcast.cn">支付成功<span>5</span>秒后跳转到首页</a>  

  <script>
    const a = document.querySelector('a')
    // 声明变量
    let num = 5
    // 定时器
    let timeId =  setInterval(function(){
      // 修改倒计时时间
      a.innerHTML = `支付成功<span>${num}</span>秒后跳转到首页`
      num--
      if (num === 0) {
        // 停止定时器
        clearInterval(timeId)
        // 跳转
        location.href = 'http://www.itcast.cn'
      }
    },1000)

  </script>
</body>

</html>
